package edu.java.homework.hw03.ipj07;

import java.util.Scanner;

public class Exer02done {

    /**
     * @param args
     */
    public static void main(String[] args) {
	Scanner input = new Scanner(System.in);
	int count = 0;
	System.out
		.println("Please, enter the count of the first Fibonacci's numbers");
	count=input.nextInt();
	//exer02a)
	printFibonacciNums(count);
	System.out.println();
	// exer02b)
	long[] fibo= new long[count];
	fibonacciNums(fibo);
	printArray(fibo);
	
	input.close();
    }

    public static void printFibonacciNums(int n) {
	if(n<=0){
	    throw new IllegalArgumentException
	    ("Incorrect input of the count of Fibonacci's numbers");
	}
	if(n==1){
	    System.out.println("fibo[0]= 1");
	    return;
	}
	if(n==2){
	    System.out.println("fibo[0]= 1");
	    System.out.println("fibo[1]= 1");
	    return;
	}
	long a1 = 1;
	long a2 = 1;
	System.out.println("fibo[0]= " + a1);
	System.out.println("fibo[1]= " + a2);
	for (int i = 2; i <= n - 1; i++) {
	    a2 = a2 + a1;
	    a1 = a2 - a1;
	    System.out.println("fibo[" + i + "]= " + a2);
	}
    }
    
    public static void fibonacciNums(long[] fibo){
	fibo[0]=1;
	fibo[1]=1;
	for(int i=2;i<fibo.length;i++){
	    fibo[i]=fibo[i-2] + fibo[i-1];
	}
    }
    
    public static void printArray(long[] array){
	for(int i=0;i<array.length;i++){
	    System.out.print(array[i] + "  ");
	}
    }

}
